package com.tjp.eight.ui.fragment.mywallet.details;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.tjp.eight.R;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/3/28.
 */
public class WalletListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    Context context;
    ArrayList<WallistRModel.WalletItemModel> models;

    public WalletListAdapter(Context context) {
        this.context = context;
        models = new ArrayList<>();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_wallet_list, parent, false);
        return new WalletListViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ((WalletListViewHolder) holder).tv_money.setText("-" + models.get(position).money);
        ((WalletListViewHolder) holder).tv_time.setText("" + models.get(position).time);
    }

    @Override
    public int getItemCount() {
        return models.size();
    }

    public void addData(ArrayList<WallistRModel.WalletItemModel> list) {
        if (list == null || list.isEmpty()) return;

        for (WallistRModel.WalletItemModel item : list) {
            models.add(item);
        }
        notifyDataSetChanged();
    }

    public void addMData(ArrayList<WallistRModel.WalletItemModel> list) {
        if (list == null || list.isEmpty()) return;

        int position = models.size();
        for (WallistRModel.WalletItemModel item : list) {
            models.add(item);
        }
        notifyItemRangeInserted(position, getItemCount());
    }

    class WalletListViewHolder extends RecyclerView.ViewHolder {
        TextView tv_tips;
        TextView tv_time;
        TextView tv_money;

        public WalletListViewHolder(View view) {
            super(view);
            tv_money = (TextView) view.findViewById(R.id.tv_money);
            tv_tips = (TextView) view.findViewById(R.id.tv_tips);
            tv_time = (TextView) view.findViewById(R.id.tv_time);
        }
    }
}
